package ${packageName}.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 多租户安全配置属性
 */
@Component
@ConfigurationProperties(prefix = "app.security")
@Data
public class TenantSecurityProperties {

    private String tenantHeader = "${securityTenantHeader}";

    private String tokenHeader = "${securityTokenHeader}";

    private String tokenPrefix = "${securityTokenPrefix}";

    private final Jwt jwt = new Jwt();

    private List<Tenant> tenants = new ArrayList<>();

    public List<Tenant> getTenants() {
        if (tenants == null) {
            return Collections.emptyList();
        }
        return tenants;
    }

    public void setTenants(List<Tenant> tenants) {
        this.tenants = tenants;
    }

    @Data
    public static class Jwt {

        private String secret = "${jwtSecret}";

        private long expirationSeconds = ${jwtExpirationSeconds}L;

        private long refreshExpirationSeconds = ${jwtRefreshExpirationSeconds}L;
    }

    @Data
    public static class Tenant {

        private String tenantId;

        private List<User> users = new ArrayList<>();
    }

    @Data
    public static class User {

        private String username;

        private String password;

        private List<String> roles = new ArrayList<>();
    }
}
